<%--
  Created by IntelliJ IDEA.
  User: 17728
  Date: 2020/10/12
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@ include file="/pages/common/head.jsp" %>
    <link type="text/css" rel="stylesheet" href="static/css/style.css">
    <link>
    <style type="text/css">
        html, body {
            margin: 0px;
            padding: 0px;
            width: 100%;
            height: 100%;
            background-image: linear-gradient(to top right, white, paleturquoise, white, peachpuff, white);
        }


        .big {
            /* background-color:cornsilk; */
            width: 450px;
            height: 420px;
            position: relative;
            border-radius: 5% 5%;
            top: 100px;
            margin: 0 auto;
            opacity: 1.5;

        }

        h2 {
            position: relative;
            text-align: center;
            top: 10px;
        }

        .small {
            width: 350px;
            height: 350px;
            position: relative;
            top: 50px;
            margin: 0 auto;
        }

        .btn-default {
            position: relative;
            left: 50px;
            top: 45px
        }

        .yan {
            position: relative;
            top: 15px;
            left: 30px;
        }

        #rad1 {
            position: relative;
            top: 40px;
            left: 30px;
        }

    </style>
    <script type="text/javascript">
        // 页面加载完成之后
        $(function () {
            // 给注册绑定单击事件
            $("#sub_btn").click(function () {
                // 验证用户名：必须由字母，数字下划线组成，并且长度为5 到12 位
                //1 获取用户名输入框里的内容
                var usernameText = $("#username").val();
                //2 创建正则表达式对象
                var usernamePatt = /^\w{3,12}$/;
                //3 使用test 方法验证
                if (!usernamePatt.test(usernameText)) {
                    //4 提示用户结果
                    $("span.errorMsg").text("用户名不合法！");
                    return false;
                }
// 验证密码：必须由字母，数字下划线组成，并且长度为5 到12 位
//1 获取用户名输入框里的内容
                var passwordText = $("#password").val();
//2 创建正则表达式对象
                var passwordPatt = /^\w{3,12}$/;
//3 使用test 方法验证
                if (!passwordPatt.test(passwordText)) {
                    //4 提示用户结果
                    $("span.errorMsg").text("密码不合法！");
                    return false;
                }
// 验证确认密码：和密码相同
//1 获取确认密码内容
                var repwdText = $("#repassword").val();
//2 和密码相比较
                if (repwdText !== passwordText) {
                    //3 提示用户
                    $("span.errorMsg").text("确认密码和密码不一致！");
                    return false;
                }

// 验证码：现在只需要验证用户已输入。因为还没讲到服务器。验证码生成。
                var codeText = $("#code").val();
//去掉验证码前后空格

                codeText = $.trim(codeText);

                if (codeText == null || codeText == "") {
                    //4 提示用户
                    $("span.errorMsg").text("验证码不能为空！");
                    return false;
                }
                $("span.errorMsg").text("");
            });
            $("#code_img").click(function () {
                // 在事件响应的function 函数中有一个this 对象。这个this 对象，是当前正在响应事件的dom 对象
                // src 属性表示验证码 img 标签的 图片路径。它可读，可写
                // alert(this.src);
                this.src = "${basePath}kaptcha.jpg?d=" + new Date();
            });
        });
    </script>
</head>
<body>
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">&nbsp;&nbsp;&nbsp;作业棒&nbsp;&nbsp;&nbsp;</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">


            <ul class="nav navbar-nav navbar-right">
                <li><a href="index.jsp">&nbsp;&nbsp;&nbsp;首页&nbsp;&nbsp;&nbsp;</a></li>
                <li><a href="pages/user/login.jsp">&nbsp;&nbsp;&nbsp;登录&nbsp;&nbsp;&nbsp;</a></li>
                <li class="active"><a href="pages/user/regist.jsp">&nbsp;&nbsp;&nbsp;注册&nbsp;&nbsp;&nbsp; <span
                        class="sr-only">(current)</span></a></li>

            </ul>
        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>
<div class="big">
    <div class="small">
        <form action="UserServlet" method="post">
            <input type="hidden" name="action" value="regist">
            <h2>用户注册</h2><br/>
            <span class="errorMsg"></span>
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" class="form-control" id="username" placeholder="Username" name="username">
            </div>
            <br/>
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" class="form-control" id="password" placeholder="Password" name="password">
            </div>
            <br/>
            <div class="form-group">
                <label for="repassword">确认密码</label>
                <input type="password" class="form-control" id="repassword" placeholder="Password" name="repassword">
            </div>
            <br/>
            <div class="form-group">
               <span class="yan"><label>验证码：</label>
                <input class="itxt" type="text" style="width: 80px;" id="code" name="code"/>
                </span>
                <img alt="" width="160px" height="55px" id="code_img"
                     src="http://localhost:8080/Work_war_exploded/kaptcha.jpg" style="float: right; margin-right: 10px">
            </div>
            <br/>
            <span id="rad1"><input type="radio" name="type" value="1">我是老师&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" name="type" value="2"> 我是学生</span>
            <button type="submit" class="btn btn-default" id="sub_btn">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注册&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</button>
        </form>
    </div>
</div>

</body>
</html>

